
import React from "react";
import {Checkbox, Form} from "antd";
import {diffProps} from "../../libs/funcs";

/**
 * 多选框
 */
class FormCheckBox extends React.Component{
    constructor(props) {
        super(props);
        this.state={}
    }

    render() {
        const {getFieldDecorator} = this.props.form;
        const {label,field,initialValue,rules} = this.props;
        const new_props = diffProps(this.props,["form","label","field","initialValue","rules"]);
        let options = this.props.options ? this.props.options : {};
        let options_list = [];
        Object.keys(options).map(key => {
            options_list.push({
                label:options[key],
                value:key
            });
            return true;
        });
        return (
            <Form.Item label={label ? label : "多选框"} {...new_props}>
                {getFieldDecorator(field ? field : 'default_check_box', {initialValue: Array.isArray(initialValue) ? initialValue : [],rules: rules ? rules : []})(
                    <Checkbox.Group options={options_list} />
                )}
            </Form.Item>
        );
    }
}

export default FormCheckBox;
